{{extend '../layout.html'}}
{{block 'body'}}
<div class="container">
  <form action="/users/login" method="post">
    <div class="form-group">
      <label for="userName">用户名</label>
      <input type="text" class="form-control" id="userName" name="userName">
    </div>
    <div class="form-group">
      <label for="password">Password</label>
      <input type="password" class="form-control" name="password" id="password" placeholder="Password">
    </div>
    <button id="sub" type="button" class="btn btn-primary">Submit</button>
    <button id="cancel" type="button" class="btn btn-default">Cancel</button>
  </form>
</div>
<script type="text/javascript">
    $('#cancel').click(function(){
        location.href = "/";
    });
    $('#sub').click(()=>{
      $.ajax({
        url:'/users/login',
        type:'post',
        dataType:'JSON',
        data:{userName:$('#userName').val(),password:$('#password').val()}
        success:res=>{
          if(res.err==1){
            swal('',res.msg,'error');
            return 
          }
          location.href = "/home";
        }
      })
    })
</script>
{{/block}}